<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产品名称" prop="commodityName">
        <el-input v-model="queryParams.commodityName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="公司id(用来进行多表联查)" prop="companyId">
        <el-input v-model="queryParams.companyId" placeholder="请输入公司id(用来进行多表联查)" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="产品出库数量" prop="commodityNum">
        <el-input v-model="queryParams.commodityNum" placeholder="请输入产品出库数量" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="产品重量" prop="commodityWeight">
        <el-input v-model="queryParams.commodityWeight" placeholder="请输入产品重量" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品规格" prop="commoditySize">
        <el-select v-model="queryParams.commoditySize" placeholder="请选择产品规格" clearable>
          <el-option v-for="dict in dict.type.commodity_size" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="生产日期" prop="produceDate">
        <el-date-picker clearable v-model="queryParams.produceDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择生产日期">
        </el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="产品种类" prop="commodityType">
        <el-select v-model="queryParams.commodityType" placeholder="请选择产品种类" clearable>
          <el-option v-for="dict in dict.type.commodity_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="产品状态" prop="commodityStatus">
        <el-select v-model="queryParams.commodityStatus" placeholder="请选择产品状态" clearable>
          <el-option v-for="dict in dict.type.commodity_status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select> -->
      <!-- </el-form-item> -->
      <!-- <el-form-item label="产品唯一编码" prop="commodityUuid">
        <el-input v-model="queryParams.commodityUuid" placeholder="请输入产品唯一编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="出货员ID" prop="staffId">
        <el-input v-model="queryParams.staffId" placeholder="请输入出货员ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="出货员" prop="commodityStaff">
        <el-input v-model="queryParams.commodityStaff" placeholder="请输入出货员" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="出货时间" prop="shipTime">
        <el-date-picker clearable v-model="queryParams.shipTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择出货时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核员ID" prop="checkId">
        <el-input v-model="queryParams.checkId" placeholder="请输入审核员ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="审核员" prop="checkStaff">
        <el-input v-model="queryParams.checkStaff" placeholder="请输入审核员" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="审核时间" prop="checkTime">
        <el-date-picker clearable v-model="queryParams.checkTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择审核时间">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table ref="singleTable" :data="productOutList" highlight-current-row @current-change="handleCurrentChange" style="width: 100%">
      <!-- <el-table-column label="产品出库id" align="center" prop="id" /> -->
      <el-table-column label="产品名称" align="center" prop="commodityName" />
      <el-table-column label="公司id(用来进行多表联查)" align="center" prop="companyId" />
      <el-table-column label="产品出库数量" align="center" prop="commodityNum" />
      <el-table-column label="产品颜色" align="center" prop="commodityColor" />
      <el-table-column label="产品重量" align="center" prop="commodityWeight" />
      <el-table-column label="产品规格" align="center" prop="commoditySize">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.commodity_size" :value="scope.row.commoditySize" />
        </template>
      </el-table-column>
      <el-table-column label="生产日期" align="center" prop="produceDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.produceDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="过期时间" align="center" prop="produceOverdate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.produceOverdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="产品种类" align="center" prop="commodityType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.commodity_type" :value="scope.row.commodityType" />
        </template>
      </el-table-column>
      <el-table-column label="产品状态" align="center" prop="commodityStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.commodity_status" :value="scope.row.commodityStatus" />
        </template>
      </el-table-column>
      <el-table-column label="产品唯一编码" align="center" prop="commodityUuid" />
      <el-table-column label="出货员ID" align="center" prop="staffId" />
      <el-table-column label="出货员" align="center" prop="commodityStaff" />
      <el-table-column label="出货时间" align="center" prop="shipTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.shipTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核员ID" align="center" prop="checkId" />
      <el-table-column label="审核员" align="center" prop="checkStaff" />
      <el-table-column label="审核时间" align="center" prop="checkTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import { listProductPass } from '@/api/trace/productOut'
export default {
  name: 'ProductOut',
  dicts: ['commodity_type', 'commodity_status', 'commodity_size'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出库商品详情表格数据
      productOutList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        commodityName: null,
        companyId: null,
        commodityNum: null,
        commodityColor: null,
        commodityWeight: null,
        commoditySize: null,
        produceDate: null,
        produceOverdate: null,
        commodityType: null,
        commodityStatus: null,
        commodityUuid: null,
        staffId: null,
        commodityStaff: null,
        shipTime: null,
        checkId: null,
        checkStaff: null,
        checkTime: null
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询出库商品详情列表 */
    getList() {
      this.loading = true
      listProductPass(this.queryParams).then(response => {
        this.productOutList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        commodityName: null,
        companyId: null,
        commodityNum: null,
        commodityColor: null,
        commodityWeight: null,
        commoditySize: null,
        produceDate: null,
        produceOverdate: null,
        commodityType: null,
        commodityStatus: null,
        commodityUuid: null,
        staffId: null,
        commodityStaff: null,
        shipTime: null,
        checkId: null,
        checkStaff: null,
        checkTime: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 单选框选中事件
    handleCurrentChange(currentRow) {
      // console.log(currentRow);
      this.$emit('uploadData', { id: currentRow.id, name: currentRow.commodityName })
    }
  }
}
</script>
